<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>预约列表</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background-color: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            margin-bottom: 20px;
        }
        .btn {
            display: inline-block;
            padding: 8px 15px;
            background-color: #4CAF50;
            color: white;
            text-decoration: none;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            margin-bottom: 20px;
        }
        .btn:hover {
            background-color: #45a049;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f2f2f2;
        }
        tr:hover {
            background-color: #f5f5f5;
        }
        .action-btn {
            padding: 5px 10px;
            margin-right: 5px;
            text-decoration: none;
            border-radius: 3px;
            color: white;
        }
        .edit-btn {
            background-color: #2196F3;
        }
        .delete-btn {
            background-color: #f44336;
        }
        .approve-btn {
            background-color: #4CAF50;
        }
        .reject-btn {
            background-color: #FF9800;
        }
        .status-pending {
            color: #FF9800;
        }
        .status-approved {
            color: #4CAF50;
        }
        .status-rejected {
            color: #f44336;
        }
        .status-completed {
            color: #2196F3;
        }
        .search-form {
            margin-bottom: 20px;
            display: flex;
            gap: 10px;
        }
        .search-form input, .search-form select {
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        .search-form button {
            padding: 8px 15px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .search-form button:hover {
            background-color: #45a049;
        }
        .alert {
            padding: 15px;
            margin-bottom: 20px;
            border-radius: 4px;
        }
        .alert-success {
            background-color: #dff0d8;
            color: #3c763d;
            border: 1px solid #d6e9c6;
        }
        .alert-danger {
            background-color: #f2dede;
            color: #a94442;
            border: 1px solid #ebccd1;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>预约列表</h1>
        
        <c:if test="${not empty success}">
            <div class="alert alert-success">${success}</div>
        </c:if>

        <c:if test="${not empty error}">
            <div class="alert alert-danger">${error}</div>
        </c:if>
        
        <div class="search-form">
            <form action="${pageContext.request.contextPath}/reservation/list" method="get">
                <input type="text" name="keyword" placeholder="搜索预约..." value="${keyword}">
                <select name="status">
                    <option value="">所有状态</option>
                    <option value="pending" ${status == 'pending' ? 'selected' : ''}>待审核</option>
                    <option value="approved" ${status == 'approved' ? 'selected' : ''}>已通过</option>
                    <option value="rejected" ${status == 'rejected' ? 'selected' : ''}>已拒绝</option>
                    <option value="completed" ${status == 'completed' ? 'selected' : ''}>已完成</option>
                </select>
                <button type="submit">搜索</button>
            </form>
        </div>
        
        <a href="${pageContext.request.contextPath}/venue/list" class="btn">返回场馆列表</a>
        
        <table>
            <thead>
                <tr>
                    <th>ID</th>
                    <th>场馆</th>
                    <th>预约人</th>
                    <th>开始时间</th>
                    <th>结束时间</th>
                    <th>用途</th>
                    <th>状态</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <c:forEach items="${reservations}" var="reservation">
                    <tr>
                        <td>${reservation.id}</td>
                        <td>${reservation.venueName}</td>
                        <td>${reservation.realName} (${reservation.username})</td>
                        <td>${reservation.startTime}</td>
                        <td>${reservation.endTime}</td>
                        <td>${reservation.purpose}</td>
                        <td class="status-${reservation.status}">
                            <c:choose>
                                <c:when test="${reservation.status == 'pending'}">待审核</c:when>
                                <c:when test="${reservation.status == 'approved'}">已通过</c:when>
                                <c:when test="${reservation.status == 'rejected'}">已拒绝</c:when>
                                <c:when test="${reservation.status == 'completed'}">已完成</c:when>
                            </c:choose>
                        </td>
                        <td><fmt:formatDate value="${reservation.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                        <td>
                            <c:if test="${reservation.status == 'pending'}">
                                <a href="${pageContext.request.contextPath}/reservation/edit/${reservation.id}" 
                                   class="action-btn edit-btn">编辑</a>
                                <a href="${pageContext.request.contextPath}/reservation/delete/${reservation.id}" 
                                   class="action-btn delete-btn"
                                   onclick="return confirm('确定要删除这个预约吗？')">删除</a>
                            </c:if>
                            
                            <c:if test="${sessionScope.user.role == 'admin' && reservation.status == 'pending'}">
                                <a href="${pageContext.request.contextPath}/reservation/updateStatus/${reservation.id}?status=approved" 
                                   class="action-btn approve-btn">通过</a>
                                <a href="${pageContext.request.contextPath}/reservation/updateStatus/${reservation.id}?status=rejected" 
                                   class="action-btn reject-btn">拒绝</a>
                            </c:if>
                            
                            <c:if test="${sessionScope.user.role == 'admin' && reservation.status == 'approved'}">
                                <a href="${pageContext.request.contextPath}/reservation/updateStatus/${reservation.id}?status=completed" 
                                   class="action-btn approve-btn">标记完成</a>
                            </c:if>
                        </td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
    </div>
</body>
</html> 